import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class FlameDemoListProvider extends ChangeNotifier {
  List _flameDemoList = [];

  List get flameDemoList => _flameDemoList;

  int get demoListLength => _flameDemoList.length;

  Future<void> initData(BuildContext context) async {
    try {
      var value =
          await rootBundle.loadString('assets/json/flame_demo_list.json');
      _flameDemoList = json.decode(value);

      // 在异步任务完成后检查是否仍然挂载在树上
      if (context.mounted) {
        notifyListeners();
      }
    } catch (e) {
      // 处理错误
      print('Error loading data: $e');
    }
  }
}